//
//  CHDictionaryExtensions.m
//  Chocolat
//
//  Created by Pieter Omvlee on 8/19/08.
//  Copyright 2008 Insearchofaname. All rights reserved.
//

#import "CHDictionaryExtensions.h"


@implementation NSDictionary (CHDictionaryExtensions)

//merges all dictionaries in the array into one dictionary. where double keys are concerned; the last dictionary wins
+ (NSDictionary *)dictionaryByMergingDictionariesInArray:(NSArray *)anArray
{
  NSMutableDictionary *result = [NSMutableDictionary dictionary];
  for (NSDictionary *dict in anArray)
    [result addEntriesFromDictionary:dict];
  
  return result;
}

//merges the two dictionaries into one dictionary. Where double keys are concerned; the last dictionary wins
+ (NSDictionary *)dictionaryByMergingDictionary:(NSDictionary *)dict1 andDictionary:(NSDictionary *)dict2
{
  return [self dictionaryByMergingDictionariesInArray:[NSArray arrayWithObjects:dict1, dict2, nil]];
}

@end
